package com.ditri.distrident.commonservice.service.impl;

import com.ditri.distrident.common.constant.ErrorCodeEnum;
import com.ditri.distrident.common.entity.Result;
import com.ditri.distrident.common.utils.SendSmsUtil;
import com.ditri.distrident.commonservice.service.SmsSendingService;
import org.springframework.data.redis.core.RedisTemplate;

import javax.annotation.Resource;

/**
 * @author: edxuanlen
 * @date: 2020-08-06 16:43
 * @version: 1.0
 **/
public class SmsSendingServiceImpl implements SmsSendingService {

    @Resource
    private RedisTemplate<String, Object> redisTemplate;

    @Override
    public Result sendSms(String phone) {
        return SendSmsUtil.sendSms(phone);
    }

    @Override
    public Result sendRegister(String phone) {
        String username = (String) redisTemplate.opsForValue().get(phone);
        if(username != null){
            return ErrorCodeEnum.THE_DEVICE_HAS_BEEN_REGISTERED.getResult();
        }
        return SendSmsUtil.sendSms(phone);
    }
}
